import { BasicColumn, FormProps } from '/@/components/Table';
import { Tag } from 'ant-design-vue';
import { t } from '/@/hooks/web/useI18n';
import moment from 'moment';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '商户订单号',
      dataIndex: 'blMerOrderNo',
      width: 160,
      align: 'left',
    },
    {
      title: '充值账号',
      dataIndex: 'rechargeAccount',
      width: 120,
      align: 'left',
    },
    {
      title: '产品编号',
      dataIndex: 'productId',
      width: 120,
      align: 'left',
    },
    {
      title: '充值量',
      dataIndex: 'rechargeValue',
      width: 120,
      align: 'left',
    },
    {
      title: '订单状态',
      dataIndex: 'orderState',
      width: 80,
      align: 'left',
    },
    {
      title: '运营商',
      dataIndex: 'ispName',
      width: 120,
      align: 'left',
    },
    {
      title: '销售价',
      dataIndex: 'productSalePrice',
      width: 120,
      align: 'left',
    },
    {
      title: '成本价',
      dataIndex: 'productCost',
      width: 120,
      align: 'left',
    },
    {
      title: '利润',
      dataIndex: 'profit',
      width: 120,
      align: 'left',
    },
    {
      title: '利润',
      dataIndex: 'profit',
      width: 120,
      align: 'left',
    },
    {
      title: '客户下单时间',
      dataIndex: 'orderTime',
      width: 180,
      align: 'left',
    },
  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    autoSubmitOnEnter: true,
    schemas: [
      {
        field: 'blMerOrderNo',
        component: 'Input',
        label: '搜索',
        colProps: {
          span: 8,
        },
        componentProps: {
          placeholder: '请输入商户订单号, 供应商订单号',
        },
      },
      {
        field: 'fieldTime',
        component: 'RangePicker',
        label: '起止日期',
        colProps: {
          span: 8,
        },
        defaultValue: [
          moment().subtract(1, 'month').format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 00:00:00'),
        ],
        componentProps: {
          valueFormat: 'YYYY-MM-DD HH:mm:ss',
        },
        dynamicRules: ({ model }) => {
          return [
            {
              required: true,
              validator: (_) => {
                if (model.fieldTime.length > 1) {
                  if (moment(model.fieldTime[1]).diff(moment(model.fieldTime[0]), 'M', true) > 1) {
                    return Promise.reject('起止日期只能在一个月内');
                  }
                  return Promise.resolve();
                }
                return Promise.resolve();
              },
            },
          ];
        },
      },
    ],
    fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
  };
}
